/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;

import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.dao.KeywordDAO;
import etcore.webapp.grouptalk.common.object.Keyword;

/**
 * KeywordService implements queries and transactions on Keyword
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class KeywordService extends BaseService {

	public Keyword findById(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			Keyword result = dao.findById(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Keyword> findByProperty(String propertyName, Object value,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			List<Keyword> result = dao.findByProperty(propertyName, value,
					begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Keyword> findByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			List<Keyword> result = dao.findByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Keyword> findBy2Properties(String propertyName, Object value,
			String propertyName2, Object value2) {

		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			List<Keyword> result = dao.findBy2Properties(propertyName, value,
					propertyName2, value2);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			long result = dao.findSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			long result = dao.searchSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List searchByProperty(String propertyName, Object value, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			List result = dao.searchByProperty(propertyName, value, begin,
					length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Keyword> findAll(int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			KeywordDAO dao = new KeywordDAO();
			List<Keyword> result = dao.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}